#include "TTimerFreq.h"
float g_fSecPerFrame = 0.0f;
bool TTimerFreq::Init()
{
	QueryPerformanceFrequency(&m_Frequency);
	memset(&m_Start, 0, sizeof(LARGE_INTEGER));
	memset(&m_End, 0, sizeof(LARGE_INTEGER));
	memset( m_strBuffer, 0, sizeof(TCHAR)* MAX_PATH );
	QueryPerformanceCounter(&m_Start);
	return true;
}
bool TTimerFreq::Frame()
{
	QueryPerformanceCounter(&m_End);
	if( m_Start.QuadPart != 0 )
	{
		m_fSecPerFrame = (m_End.LowPart-m_Start.LowPart) / 
			(float)(m_Frequency.LowPart);
		g_fSecPerFrame = m_fSecPerFrame;
	}else
	{
		m_fSecPerFrame = 0.0f;
	}

	m_Accumulation+= m_fSecPerFrame;
	m_fFrameTime += m_fSecPerFrame;

	if( m_fFrameTime >= 1.0f)
	{
		m_iFPSCnt = m_iTmpTime;
		m_iTmpTime = 0;
		m_fFrameTime = m_fFrameTime - 1.0f;
	}
	m_iTmpTime++;

	m_Start = m_End;

	_stprintf_s( m_strBuffer, _T("FPS:%d, %10.6f %10.6f"), 
		   m_iFPSCnt,m_fSecPerFrame, m_Accumulation );
	return true;
}
bool TTimerFreq::Render()
{
	return true;
}
bool TTimerFreq::Release()
{
	return true;
}
TTimerFreq::TTimerFreq(void)
{
	m_iFPSCnt		= 0;
	m_fSecPerFrame	= 0;;
	m_Accumulation	= 0.0f;
	m_fFrameTime	= 0.0f;
	m_iTmpTime		= 0;
}

TTimerFreq::~TTimerFreq(void)
{
}
